package com.jinlei.crm.workbench.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jinlei.crm.workbench.dao.ActivityDao;
import com.jinlei.crm.workbench.entity.Activity;
import com.jinlei.crm.workbench.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 市场活动表(Activity)表服务实现类
 *
 * @author makejava
 * @since 2022-07-02 15:05:33
 */
@Service
public class ActivityServiceImpl implements ActivityService {

    @Autowired
    private ActivityDao activityDao;

    @Override
    public Activity findById(String id) {
        return activityDao.selectById(id);
    }

    @Override
    public Map<String, Object> ListPage(Integer pageNumber, Integer pageSize, Activity activity) {
        PageHelper.startPage(pageNumber, pageSize);
        PageInfo<Activity> pageInfo = new PageInfo<>(activityDao.select(activity));
        Map<String, Object> pageMap = new HashMap<>();
        pageMap.put("list", pageInfo.getList());
        pageMap.put("total", pageInfo.getTotal());
        return pageMap;
    }

    @Override
    public boolean save(Activity activity) {
        return activityDao.insert(activity) > 0;
    }

    @Override
    public boolean edit(Activity activity) {
        return activityDao.update(activity) > 0;
    }

    @Override
    public boolean deleteById(String id) {
        return activityDao.deleteById(id) > 0;
    }

    @Override
    public boolean deleteBatch(String[] ids) {
        return activityDao.deleteBatch(ids) > 0;
    }

    @Override
    public Map<String, Object> selectByClueId(Integer pageNumber, Integer pageSize, String clueId) {
        PageHelper.startPage(pageNumber,pageSize);
        List<Activity> list = activityDao.selectByClueId(clueId);
        PageInfo<Activity> pageInfo = new PageInfo<>(list);
        Map<String, Object> pageMap = new HashMap<>();
        pageMap.put("list",pageInfo.getList());
        pageMap.put("total",pageInfo.getTotal());
        return pageMap;
    }

    @Override
    public Map<String, Object> selectList(Integer pageNumber, Integer pageSize, String name, String clueId) {
        PageHelper.startPage(pageNumber,pageSize);
        PageInfo<Activity> pageInfo = new PageInfo(activityDao.selectOn(name,clueId));
        Map<String, Object> pageMap = new HashMap<>();
        pageMap.put("list",pageInfo.getList());
        pageMap.put("total",pageInfo.getTotal());
        return pageMap;
    }
}
